package com.fita.admin.entity.search.client;

import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import com.fita.admin.entity.search.AbstractSearch;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: 11200
 * @date: 2019/6/26
 */
public class ClientInterviewRecordSearch extends AbstractSearch {

    private List<Long> clientIds;

    private List<Long> principalIds;

    /**
     * get prepared filter
     *
     * @param refresh whether to re-create filter
     * @return
     */
    public QueryFilter getPreparedFilter(boolean refresh) {
        if (filter == null || refresh) {

            filter = new QueryFilter();

            filter.addSentence("client.id IN (:clientIds)" ,"clientIds", clientIds);

            filter.addSentence("principal.id IN (:principals)", "principals", principalIds);
        }
        if (order == null){
            order = new QueryOrder();
            order.add("id", "DESC");
        }
        return filter;    }

    /**
     * build query string template (sql or hql with :keys)
     *
     * @return
     */
    public String buildSentenceTemplate() {
        return "FROM ClientInterviewRecord WHERE disabled = false " + getPreparedFilter(false).clauseSentence() + getOrder().sentence();
    }

    /**
     * 添加principal id
     * @param principalId
     */
    public void addPrincipalId(Long principalId) {
        if (principalIds == null) {
            principalIds = new ArrayList<>();
        }
        principalIds.add(principalId);
    }

    public List<Long> getClientIds() {
        return clientIds;
    }

    public void setClientIds(List<Long> clientIds) {
        this.clientIds = clientIds;
    }

    public List<Long> getPrincipalIds() {
        return principalIds;
    }

    public void setPrincipalIds(List<Long> principalIds) {
        this.principalIds = principalIds;
    }
}
